package com.pda.xinma.ui.handingin;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.pda.xinma.R;
import com.pda.xinma.adapter.HandingInStaticsAdapter;
import com.pda.xinma.bean.HandingInStaticsBean;
import com.pda.xinma.contract.HandingInStaticsContract;
import com.pda.xinma.dialog.AffirmDialog;
import com.pda.xinma.presenter.HandingInStaticsPresenter;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpFragment;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

public class HandingInStaticsFragment extends BaseMvpFragment<HandingInStaticsPresenter> implements HandingInStaticsContract.View {
    HandingInStaticsAdapter adapter;
    @BindView(R.id.tv_deliveryNo)
    TextView tvDeliveryNo;
    @BindView(R.id.rv_content)
    RecyclerView rvContent;
    @BindView(R.id.bt_close)
    Button btClose;
    @BindView(R.id.fl_close)
    FrameLayout flClose;

    public HandingInStaticsFragment(String entryNo) {
        this.entryNo = entryNo;
    }

    public HandingInStaticsFragment() {
    }

    private String entryNo;
    private String entryNoStatus;

    public HandingInStaticsFragment(String entryNo, String entryNoStatus) {
        this.entryNo = entryNo;
        this.entryNoStatus = entryNoStatus;
    }

    @Override
    public HandingInStaticsPresenter getPresenter() {
        return new HandingInStaticsPresenter();
    }

    @Override
    public int getViewId() {
        return R.layout.fragment_statistics;
    }

    @Override
    public void initView() {
        EventBus.getDefault().register(this);
        if (entryNoStatus.equals("10") || entryNoStatus.equals("20")){
            btClose.setVisibility(View.VISIBLE);
        }else {
            btClose.setVisibility(View.GONE);
        }
        tvDeliveryNo.setText("入库单信息 " + entryNo);
        adapter = new HandingInStaticsAdapter(R.layout.item_hand_in_statistics, new ArrayList<>());
        rvContent.setAdapter(adapter);
        if (!TextUtils.isEmpty(entryNo)){
            presenter.entryStatistics(entryNo);
        }
        //
    }

    @Override
    public void initLinsenterner() {

    }
    @Subscribe
    public void onEvent(String entry){
        entryNo=entry;
        tvDeliveryNo.setText("入库单信息 " + entryNo);
        presenter.entryStatistics(entryNo);
    }
    @Override
    public void getData() {

    }

    @Override
    public void setStatistics(HandingInStaticsBean bean) {
        adapter.setNewInstance(bean.getInfoVoList());
    }

    @OnClick(R.id.bt_close)
    public void onViewClicked() {
        AffirmDialog affirmDialog=new AffirmDialog(mContext, new AffirmDialog.OnConfrim() {
            @Override
            public void onConfrim() {
                presenter.entryClose(entryNo);
            }
        });
        affirmDialog.show("确认要关闭该单子？");
    }
}
